local blaze = require "blaze"
local app = require "app"
local gamelib = require "club.threecard.gamelib"

local M = gamelib.ui.activity()

function M:ctor()
    if app.screen.ratio > 1 then
        self.res = "club.threecard.gamelib/ui/manual.b:ManualUI - Landscape"
    else
        self.res = "club.threecard.gamelib/ui/manual.b:ManualUI - Portrait"
    end

    local TabHeaderList = require "ui.Common.TabHeaderList"
    local TabHeaderItem = require "ui.Common.TabHeaderItem"

    self.tab_router_view = app.ui.create_router_view("/club.threecard.blackjack/manual")
    self.tab_headers = TabHeaderList.new(TabHeaderItem)
end

function M:on_injected(bind)
    bind("button.click", self.close_button, self.on_close_click)
    bind("button.click", self.mask_button, self.on_close_click)
    bind("shortcut.escape", self.close_button.gameObject, self.on_close_click)
    self.tab_headers:set_parent(self.headers_root)
    self.tab_router_view:mount(self.pages_root)
end

function M:after_route_enter(to, from)
    self:super("after_route_enter", to, from)
    
    local route = app.router.current().matched[1]
    self.tab_headers:fill(route.children)
end


function M:before_route_update(to, from, next)
    self.tab_headers:before_route_update(to, from)
    next()
end

function M:on_close_click()
    app.router.back()
end

function M:on_release()
    self.tab_headers:release()
    self.tab_router_view:release()
end

return M